﻿<%@ WebHandler Language="C#" Class="ZSProblemLookBoardHanlder" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class ZSProblemLookBoardHanlder : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private static ZSProblemLookBoardBusiness pdb = new ZSProblemLookBoardBusiness();
    public void ProcessRequest(HttpContext context)
    {
        //本月问题回复比
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetZSThisMonthProblemRate")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();

            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"].ToString());
            }

            DataTable dt = pdb.GetZSThisMonthProblemRate(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //问题上报总数
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetZSProblemTotalCountData")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();

            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"].ToString());
            }

            DataTable dt = pdb.GetZSProblemTotalCountData(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //责任单位--生产问题回复情况
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetRespWorkcenterProblemData")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();

            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"].ToString());
            }

            DataTable dt = pdb.GetRespWorkcenterProblemData(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //提出单位--生产问题回复情况
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetZSCreateWorkcenterProblemData")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();

            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"].ToString());
            }

            DataTable dt = pdb.GetZSCreateWorkcenterProblemData(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //问题上报总数--明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetTotalProblemDataDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            para["page"] = context.Request.Form["page"].ToString();
            para["rows"] = context.Request.Form["rows"].ToString();
            para["createWorkcenter"] = context.Request.Form["cwc"].ToString();
            para["resWorkcenter"] = context.Request.Form["rwc"].ToString();


            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetProblemDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //超期总数--明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetTotalChaoQiDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            para["page"] = context.Request.Form["page"].ToString();
            para["rows"] = context.Request.Form["rows"].ToString();
            para["createWorkcenter"] = context.Request.Form["cwc"].ToString();
            para["resWorkcenter"] = context.Request.Form["rwc"].ToString();

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetTotalChaoQiDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //回复总数--明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetHuiFuDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            para["page"] = context.Request.Form["page"].ToString();
            para["rows"] = context.Request.Form["rows"].ToString();
            para["createWorkcenter"] = context.Request.Form["cwc"].ToString();
            para["resWorkcenter"] = context.Request.Form["rwc"].ToString();


            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetHuiFuDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //关闭总数--明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetGuanBiDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            para["page"] = context.Request.Form["page"].ToString();
            para["rows"] = context.Request.Form["rows"].ToString();
            para["createWorkcenter"] = context.Request.Form["cwc"].ToString();
            para["resWorkcenter"] = context.Request.Form["rwc"].ToString();


            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetGuanBiDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}